/**
 * 2018年11月27日上午11:57:51
 * @author 谢进财
 */
package com.baihang.project.ds.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baihang.framework.dao.Record;
import com.baihang.framework.kit.JsonKit;
import com.baihang.framework.kit.ModelKit;
import com.baihang.framework.service.BaseService;
import com.baihang.project.ds.dao.TextEditorDao;
import com.baihang.project.ds.model.TextEditorModel;

@Service
public class TextEditorService extends BaseService {
	@Autowired
	private TextEditorDao dao;
	
	public String getGrid() {
		int count = dao.queryForInt("select count(*) from html");
		
		List<Record> list = dao.queryForRecordList("select * from html");
		String jsonRecord = JsonKit.listToJson(list, 1);
		StringBuilder sb = new StringBuilder("{");
		sb.append("\"Rows\":"+jsonRecord+",");
		sb.append("\"Total\":"+count);
		sb.append("}");
		return sb.toString();
	}
	
	public boolean ueditorSave(int Id,String HtmlName,String HtmlContent,String HtmlRemark) {
		TextEditorModel model = new TextEditorModel();
		model.setId(Id);
		model.setName(HtmlName);
		model.setContent(HtmlContent);
		model.setRemark(HtmlRemark);
		int result = dao.update(ModelKit.modelToUpdateSqlHaveKey(model, "Id", "0"));
		if(result>0) {
			return true;
		}
		return false;
	}
	
}
